const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    page:1,
    pageSize:10,
    isEnd:false,
    contentlistdata:[],
    isloading:false,
  },
  onLoad() {

  },
  onShow(){
    if(!wx.getStorageSync('logintoken')){
      app.ToLogin()
      return
    }
    this.setData({
      page:1,
      pageSize:10,
      isEnd:false,
      contentlistdata:[],
    })
    this.deliverylist()
  },
  
  golink(e){
    if(!wx.getStorageSync('logintoken')){
      app.goLogin()
      return
    }
    var item=e.currentTarget.dataset.item;
    if(item.jobStatus==-1){
      wx.showModal({
        title: '',
        content: '该岗位已停止招聘',
        showCancel:false,
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
      return
    }
    wx.navigateTo({
      url:e.currentTarget.dataset.url
    });
  },
  
  godetail(e){
    var item=e.currentTarget.dataset.item;
    wx.navigateTo({
      url:"/pages/detail/detail?id="+item.id
    });
    
  },
  deliverylist(){
    var data={
      page:this.data.page,
      pageSize:this.data.pageSize,
    }
    Controller.deliverylist(data).then(res=>{
      if(res.data.baseData && res.data.baseData.list.length>0){
        this.setData({
          contentlistdata:this.data.contentlistdata.concat(res.data.baseData.list),
        })
      }
      if(res.data.baseData.lastPage){
        this.setData({
          isEnd:res.data.baseData.lastPage
        })
      }
      this.setData({
        isloading:false
      })
    })
  },
  onReachBottom(){
    if(this.data.isEnd){
      return
    }else{
      this.setData({
        page:this.data.page+1
      })
      this.deliverylist()
    }
    
  },
  onPageScroll: function (e) { // 获取滚动条当前位置
    
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },

})